package com.app.network;

import com.app.network.entity.NetWorkTestEntity;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;

@Module
public class NetWorkModule {

    private static final String BASE_URL = "https://api.github.com/";

    @Provides
    public NetWorkTestEntity providerNetWorkTestEntity() {

        return new NetWorkTestEntity();
    }

    @Provides
    public OkHttpClient providerOkHttpClient() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();


        return builder.build();
    }

    @Provides
    public Retrofit providerRetrofit(OkHttpClient client) {

        return new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(JacksonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(client)
                .build();
    }

    @Provides
    public ApiManager providerApiManager(Retrofit retrofit) {

        return retrofit.create(ApiManager.class);
    }



}
